# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Maintainer: kpcyrd <kpcyrd[at]archlinux[dot]org>
# Contributor: alexiobash < me (at) alexiobash (dot) com >

pkgname=wpscan
pkgver=3.8.25
pkgrel=1
epoch=1
pkgdesc='Black box WordPress vulnerability scanner'
url='https://wpscan.org'
arch=('loong64' 'x86_64')
license=('custom:WPScan')
depends=('ruby-bundler' 'libxslt' 'libyaml' 'curl' 'libxml2')
optdepends=('metasploit')
options=('!strip' '!emptydirs')
install=wpscan.install
source=(https://github.com/wpscanteam/wpscan/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha512sums=('505914962048498d081d24512cef1a9b0346cdad7c146b012e1a486b47b07641adc11a48893a8ffa305a95ab7a1150d9a7eff8594465c6688575e7d9cf2732b8')
b2sums=('b4c8246cbba00547e5044c0c5b840f281d3c3f54e312da07fa8ad51205e070dfd79f1ff850ac11d8698aa27ff2f4a5eb592cd16b0e53a9dfae83f3a4e808ded4')

prepare() {
  cd ${pkgname}-${pkgver}
  sed -i '/bundler/ s|~>|>=|g' $pkgname.gemspec
  bundle config build.nokogiri --use-system-libraries
  bundle config set --local path vendor/bundle
  bundle config set --local without development test
}

build() {
  cd ${pkgname}-${pkgver}
  CFLAGS+=" -I/usr/include/libxml2"
  bundle install -j"$(nproc)"
  # reproducible builds: don't leak jobs count
  sed '/BUNDLE_JOBS/d' -i .bundle/config
}

package() {
  cd ${pkgname}-${pkgver}

  install -d "${pkgdir}/opt/${pkgname}"
  cp -ra --no-preserve=owner . "${pkgdir}/opt/${pkgname}"

  install -d "${pkgdir}/usr/bin"
  cat > "${pkgdir}/usr/bin/${pkgname}" << EOF
#!/bin/sh
BUNDLE_GEMFILE=/opt/${pkgname}/Gemfile bundle exec ruby /opt/wpscan/bin/wpscan "\$@"
EOF
  chmod 755 "${pkgdir}/usr/bin/${pkgname}"

  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -Dm 644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}"

  rm -rf "${pkgdir}"/opt/wpscan/spec
  cd "${pkgdir}"/opt/wpscan/vendor/bundle/ruby/*
  rm -rf cache gems/*/{ext,lib/*/*.so} \
    extensions/*/*/*/{mkmf.log,gem_make.out}
}

# vim: ts=2 sw=2 et:
